import type { RuleObject } from "ant-design-vue/lib/form/interface";
import { ref, computed, unref, Ref } from "vue";

export enum LoginStateEnum {
  LOGIN,
  REGISTER,
  RESET_PASSWORD,
  MOBILE,
  QR_CODE
}

const currentState = ref(LoginStateEnum.LOGIN);

export function useLoginState() {
  function setLoginState(state: LoginStateEnum) {
    currentState.value = state;
  }

  const getLoginState = computed(() => currentState.value);

  function handleBackLogin() {
    setLoginState(LoginStateEnum.LOGIN);
  }

  return { setLoginState, getLoginState, handleBackLogin };
}

function createRule(message: string) {
  return [
    {
      required: true,
      message,
      trigger: "change"
    }
  ];
}
